package com.xbongbong.saas.script.tempenum;

import com.xbongbong.paas.enums.DefaultTypeEnum;
import com.xbongbong.paas.enums.DefaultValueEnum;
import com.xbongbong.paas.help.FormDataFormExplainHelper;
import com.xbongbong.paas.field.DefaultAttrPoJo;
import com.xbongbong.paas.field.FieldAttrEntity;
import com.xbongbong.paas.field.LinkDetailPojo;
import com.xbongbong.pro.enums.AmountFlagEnum;
import com.xbongbong.pro.enums.SaasMarkEnum;
import com.xbongbong.paas.field.SaasParticularAttributePoJo;
import com.xbongbong.saas.enums.CustomerStatementStatisticEnum;
import com.xbongbong.saas.enums.RedundantTemplateTypeEnum;
import com.xbongbong.saas.enums.XbbRefTypeEnum;
import com.xbongbong.saas.enums.dictionary.ArchivedEnum;
import com.xbongbong.saas.script.help.InitExplainsHelper;
import com.xbongbong.sys.enums.RoleEnum;
import lombok.Getter;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

/**
 * @author zcp
 * @version v1.0
 * @since v1.0
 */
@Getter
public enum TempCustomerStatementStatisticEnum {
    //对账日期
    BASE_INFO(CustomerStatementStatisticEnum.BASE_INFO),
    STATEMENT_NO(CustomerStatementStatisticEnum.STATEMENT_NO),
    CUSTOMER_ID(CustomerStatementStatisticEnum.CUSTOMER_ID),
    CHECK_DATE(CustomerStatementStatisticEnum.CHECK_DATE),
    CREATE_DATE(CustomerStatementStatisticEnum.CREATE_DATE),
    OWNER_ID(CustomerStatementStatisticEnum.OWNER_ID),
    ACCOUNTS_INFO(CustomerStatementStatisticEnum.ACCOUNTS_INFO),
    AMOUNT_RECEIVABLE_TOTAL(CustomerStatementStatisticEnum.AMOUNT_RECEIVABLE_TOTAL),
    AMOUNT_RECEIVED_TOTAL(CustomerStatementStatisticEnum.AMOUNT_RECEIVED_TOTAL),
    WRITE_OFF_AMOUNT_TOTAL(CustomerStatementStatisticEnum.WRITE_OFF_AMOUNT_TOTAL),
    BALANCE_RECEIVABLE_TOTAL(CustomerStatementStatisticEnum.BALANCE_RECEIVABLE_TOTAL),
    LINK_CUSTOMER(CustomerStatementStatisticEnum.LINK_CUSTOMER),
    SYSTEM_INFO(CustomerStatementStatisticEnum.SYSTEM_INFO),
    CREATOR(CustomerStatementStatisticEnum.CREATOR),
    ADD_TIME(CustomerStatementStatisticEnum.ADD_TIME),
    UPDATE_TIME(CustomerStatementStatisticEnum.UPDATE_TIME),
    CONFIRMOR_LINK_TEXT(CustomerStatementStatisticEnum.CONFIRMOR_LINK_TEXT),
    ;

    private CustomerStatementStatisticEnum anEnum;

    TempCustomerStatementStatisticEnum(CustomerStatementStatisticEnum anEnum) {
        this.anEnum = anEnum;
    }

    public static List<TempCustomerStatementStatisticEnum> getAllEnum() {
        List<TempCustomerStatementStatisticEnum> list = new ArrayList<>();
        Collections.addAll(list, values());
        return list;
    }

    public static void initStatementNo(FieldAttrEntity fieldAttrEntity) {
        LinkDetailPojo linkDetailPojo = new LinkDetailPojo();
        linkDetailPojo.setBusinessType(XbbRefTypeEnum.CUSTOMER_STATEMENT_STATISTIC.getCode());
        linkDetailPojo.setSubBuisenssType(XbbRefTypeEnum.CUSTOMER_STATEMENT_STATISTIC.getCode());
        linkDetailPojo.setSaasMark(SaasMarkEnum.SAAS.getCode());
        linkDetailPojo.setAttr(STATEMENT_NO.getAnEnum().getAttr());
        fieldAttrEntity.setLinkDetail(linkDetailPojo);
        fieldAttrEntity.setNoRepeat(1);
        fieldAttrEntity.setSerialNumber(InitExplainsHelper.setSerialNumber(SerialNumberEnum.CUSTOMER_STATEMENT_STATISTIC));
        fieldAttrEntity.setIsForbidden(0);
    }

    public static void initCustomerId(FieldAttrEntity fieldAttrEntity) {
        fieldAttrEntity.setLinkedText(LINK_CUSTOMER.anEnum.getAttr());
        fieldAttrEntity.setLinkedType(RedundantTemplateTypeEnum.CUSTOMER.getCode());
        SaasParticularAttributePoJo saasParticularAttributePoJo = new SaasParticularAttributePoJo();
        saasParticularAttributePoJo.setMultiCheck(false);
        saasParticularAttributePoJo.setRelyMode("customer");
        saasParticularAttributePoJo.setRelyType("base");
        fieldAttrEntity.setSaasParticularAttributePoJo(saasParticularAttributePoJo);
        fieldAttrEntity.setIsForbidden(0);
        fieldAttrEntity.setDisableListSort(1);
    }

    public static void initAmountReceivableTotal(FieldAttrEntity fieldAttrEntity) {
        fieldAttrEntity.setSummaryFlag(1);
        fieldAttrEntity.setAmountFlag(AmountFlagEnum.YES.getType());
        fieldAttrEntity.setIsForbidden(0);
    }

    public static void initAmountReceivedTotal(FieldAttrEntity fieldAttrEntity) {
        fieldAttrEntity.setSummaryFlag(1);
        fieldAttrEntity.setAmountFlag(AmountFlagEnum.YES.getType());
        fieldAttrEntity.setIsForbidden(0);
    }

    public static void initWriteOffAmountTotal(FieldAttrEntity fieldAttrEntity) {
        fieldAttrEntity.setSummaryFlag(1);
        fieldAttrEntity.setAmountFlag(AmountFlagEnum.YES.getType());
        fieldAttrEntity.setIsForbidden(0);
    }

    public static void initBalanceReceivableTotal(FieldAttrEntity fieldAttrEntity) {
        fieldAttrEntity.setSummaryFlag(1);
        fieldAttrEntity.setAmountFlag(AmountFlagEnum.YES.getType());
        fieldAttrEntity.setIsForbidden(0);
    }

    public static void initIsArchived(FieldAttrEntity fieldAttrEntity) {
        fieldAttrEntity.setItems(InitExplainsHelper.setCombItemByEnum(ArchivedEnum.class, fieldAttrEntity.getFieldType()));
    }

    public static void initOwnerId(FieldAttrEntity fieldAttrEntity) {
        fieldAttrEntity.setRequired(1);
        //可新增权限：默认【超级管理员、销售主管、创建人、负责人、负责人主管】可新增负责人，支持自定义；
        fieldAttrEntity.setShowEditable(0);
        fieldAttrEntity.setAdd(1);
        fieldAttrEntity.setAddAdvanceEnable(1);
        fieldAttrEntity.setShowAdd(1);
        //可删除权限：默认【超级管理员、销售主管】可删除负责人，支持自定义；
        fieldAttrEntity.setRemove(1);
        fieldAttrEntity.setRemoveAdvanceEnable(1);
        fieldAttrEntity.setShowRemove(1);
        fieldAttrEntity.setMultiple(1);
        fieldAttrEntity.setIsForbidden(0);
        fieldAttrEntity.setEditable(1);
        fieldAttrEntity.setUnableEditMemo(null);
        fieldAttrEntity.setAddRule(FormDataFormExplainHelper.getDefaultRule(RoleEnum.MANAGER));
        fieldAttrEntity.setRemoveRule(FormDataFormExplainHelper.getDefaultRule(RoleEnum.MANAGER));
    }

    public static void initCreator(FieldAttrEntity fieldAttrEntity) {
        fieldAttrEntity.setIsForbidden(0);
        DefaultAttrPoJo defaultAttrPoJo = new DefaultAttrPoJo();
        defaultAttrPoJo.setDefaultType(DefaultTypeEnum.DYNAMIC.getAlias());
        defaultAttrPoJo.setDefaultValue(DefaultValueEnum.LOGIN_USER.getValue());
        fieldAttrEntity.setDefaultAttr(defaultAttrPoJo);
    }
}
